//--------------------------------------- NOTES ------------------------------------------------------//
* This table is Table A12 in the paper 
//--------------------------------------------------------------------------------------------------------//

cd  "/YOUR_LOCAL_DIRECTORY" //setting the working directory
clear all //remove all data, labels, matrices etc (incl. Mata functions)
use game_state_pilot_data.dta, clear

* Create the key treatment variable
gen byte status_quo = treatment=="status_quo"
la var status_quo  "Status Quo"

* Create 2 row for each observation
expand 2, gen(dupindicator)

* Generate blue ball count variable 
gen urn_blue = player2highbluecount if dupindicator==1 // blue count for high blue urn 
replace urn_blue = player2lowbluecount if dupindicator==0 // blue count for high blue urn 

* High blue urn indicator
gen byte highballurn = dupindicator==1
la var highballurn  "High Blue Urn"
* Indicator of whether urn was transplanted:
gen transplanted_thisurn = 0
replace transplanted_thisurn=1 if player2action=="MixWithLowBlue" & dupindicator==0
replace transplanted_thisurn=1 if player2action=="MixWithHighBlue" & dupindicator==1

* Expected blue given actual TX decisions

gen expected_mortality = 1-urn_blue/100 if transplanted_thisurn==0
replace expected_mortality = 1-(urn_blue+player1bluecount)/200 if transplanted_thisurn==1

* indicator for very high risk or very low risk patients
gen byte extremepatient = player2highbluecount>=90 | player2lowbluecount<=10

* Make table (components)

* Make table (Pilot 1)

eststo clear

eststo: quietly reg expected_mortality  status_quo if pilot==1,  vce(cluster room) // Compare expected mortality rate by treatment group
eststo: quietly reg expected_mortality  status_quo if dupindicator==0 & pilot==1,  vce(cluster room) // Compare expected mortality rate by treatment group
eststo: quietly reg expected_mortality  status_quo if dupindicator==1 & pilot==1,  vce(cluster room) // Compare expected mortality rate by treatment group

eststo: quietly reg expected_mortality  status_quo if extremepatient==1 & pilot==1,  vce(cluster room) // Compare expected mortality rate by treatment group
eststo: quietly reg expected_mortality  status_quo if dupindicator==0 & extremepatient==1 & pilot==1,  vce(cluster room) // Compare expected mortality rate by treatment group
eststo: quietly reg expected_mortality  status_quo if dupindicator==1 & extremepatient==1 & pilot==1,  vce(cluster room) // Compare expected mortality rate by treatment group

eststo: quietly reg expected_mortality  status_quo if extremepatient==0 & pilot==1,  vce(cluster room) // Compare expected mortality rate by treatment group
eststo: quietly reg expected_mortality  status_quo if dupindicator==0 & extremepatient==0 & pilot==1,  vce(cluster room) // Compare expected mortality rate by treatment group
eststo: quietly reg expected_mortality  status_quo if dupindicator==1 & extremepatient==0 & pilot==1,  vce(cluster room) // Compare expected mortality rate by treatment group


esttab using table_expectedmortality_pilot1_a12.tex, se r2  keep(status_quo _cons) star(+ 0.1 * 0.05 ** 0.01)

* Make table (Pilot 2)

eststo clear

eststo: quietly reg expected_mortality  status_quo if pilot==2,  vce(cluster room) // Compare expected mortality rate by treatment group
eststo: quietly reg expected_mortality  status_quo if dupindicator==0 & pilot==2,  vce(cluster room) // Compare expected mortality rate by treatment group
eststo: quietly reg expected_mortality  status_quo if dupindicator==1 & pilot==2,  vce(cluster room) // Compare expected mortality rate by treatment group

*eststo: quietly reg expected_mortality  status_quo if extremepatient==1 & pilot==2,  vce(cluster room) // Compare expected mortality rate by treatment group - STAR-ed out because parameter settings ruled out At Least One Urn Sickest or Healthiest
*eststo: quietly reg expected_mortality  status_quo if dupindicator==0 & extremepatient==1 & pilot==2,  vce(cluster room) // Compare expected mortality rate by treatment group - STAR-ed out because parameter settings ruled out At Least One Urn Sickest or Healthiest
*eststo: quietly reg expected_mortality  status_quo if dupindicator==1 & extremepatient==1 & pilot==2,  vce(cluster room) // Compare expected mortality rate by treatment group - STAR-ed out because parameter settings ruled out At Least One Urn Sickest or Healthiest

eststo: quietly reg expected_mortality  status_quo if extremepatient==0 & pilot==2,  vce(cluster room) // Compare expected mortality rate by treatment group
eststo: quietly reg expected_mortality  status_quo if dupindicator==0 & extremepatient==0 & pilot==2,  vce(cluster room) // Compare expected mortality rate by treatment group
eststo: quietly reg expected_mortality  status_quo if dupindicator==1 & extremepatient==0 & pilot==2,  vce(cluster room) // Compare expected mortality rate by treatment group


esttab using table_expectedmortality_pilot2_a12.tex, se r2  keep(status_quo _cons) star(+ 0.1 * 0.05 ** 0.01)

* Make table (Pilot 3)

eststo clear

eststo: quietly reg expected_mortality  status_quo if pilot==3,  vce(cluster room) // Compare expected mortality rate by treatment group
eststo: quietly reg expected_mortality  status_quo if dupindicator==0 & pilot==3,  vce(cluster room) // Compare expected mortality rate by treatment group
eststo: quietly reg expected_mortality  status_quo if dupindicator==1 & pilot==3,  vce(cluster room) // Compare expected mortality rate by treatment group

*eststo: quietly reg expected_mortality  status_quo if extremepatient==1 & pilot==3,  vce(cluster room) // Compare expected mortality rate by treatment group - STAR-ed out because parameter settings ruled out At Least One Urn Sickest or Healthiest
*eststo: quietly reg expected_mortality  status_quo if dupindicator==0 & extremepatient==1 & pilot==3,  vce(cluster room) // Compare expected mortality rate by treatment group - STAR-ed out because parameter settings ruled out At Least One Urn Sickest or Healthiest
*eststo: quietly reg expected_mortality  status_quo if dupindicator==1 & extremepatient==1 & pilot==3,  vce(cluster room) // Compare expected mortality rate by treatment group - STAR-ed out because parameter settings ruled out At Least One Urn Sickest or Healthiest

eststo: quietly reg expected_mortality  status_quo if extremepatient==0 & pilot==3,  vce(cluster room) // Compare expected mortality rate by treatment group
eststo: quietly reg expected_mortality  status_quo if dupindicator==0 & extremepatient==0 & pilot==3,  vce(cluster room) // Compare expected mortality rate by treatment group
eststo: quietly reg expected_mortality  status_quo if dupindicator==1 & extremepatient==0 & pilot==3,  vce(cluster room) // Compare expected mortality rate by treatment group


esttab using table_expectedmortality_pilot3_a12.tex, se r2  keep(status_quo _cons) star(+ 0.1 * 0.05 ** 0.01)

* Make table (Pilot 4)

eststo clear

eststo: quietly reg expected_mortality  status_quo if pilot==4,  vce(cluster room) // Compare expected mortality rate by treatment group
eststo: quietly reg expected_mortality  status_quo if dupindicator==0 & pilot==4,  vce(cluster room) // Compare expected mortality rate by treatment group
eststo: quietly reg expected_mortality  status_quo if dupindicator==1 & pilot==4,  vce(cluster room) // Compare expected mortality rate by treatment group

eststo: quietly reg expected_mortality  status_quo if extremepatient==1 & pilot==4,  vce(cluster room) // Compare expected mortality rate by treatment group
eststo: quietly reg expected_mortality  status_quo if dupindicator==0 & extremepatient==1 & pilot==4,  vce(cluster room) // Compare expected mortality rate by treatment group
eststo: quietly reg expected_mortality  status_quo if dupindicator==1 & extremepatient==1 & pilot==4,  vce(cluster room) // Compare expected mortality rate by treatment group

eststo: quietly reg expected_mortality  status_quo if extremepatient==0 & pilot==4,  vce(cluster room) // Compare expected mortality rate by treatment group
eststo: quietly reg expected_mortality  status_quo if dupindicator==0 & extremepatient==0 & pilot==4,  vce(cluster room) // Compare expected mortality rate by treatment group
eststo: quietly reg expected_mortality  status_quo if dupindicator==1 & extremepatient==0 & pilot==4,  vce(cluster room) // Compare expected mortality rate by treatment group


esttab using table_expectedmortality_pilot4_a12.tex, se r2  keep(status_quo _cons) star(+ 0.1 * 0.05 ** 0.01)
